package com.jobanalysis.job_analysis.mapreduce.areaSalary;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 把数据切分，以地区为key，薪资和公司为value
 */
public class JobPredMap extends Mapper<Object, Text, Text, Text> {

    @Override
    protected void map(Object key, Text value, Context context) throws IOException, InterruptedException {

        String[] splitData = value.toString().split("\t");
        if ((splitData[1]).contains("city") && splitData.length > 8) {
            if (splitData[1].split(":").length > 1 && splitData[8].split(":").length > 1) {
                Text text = new Text(splitData[1].split(":")[1]);
                if (text.toString().contains("-")) {
                    text = new Text(text.toString().split("-")[0]);
                }
                context.write(text, new Text(splitData[8].split(":")[1]));
            }
            //key为城市，value为薪资
        }
    }
}

